/*
 * VatTypeOT.java
 *
 * $Id: VatTypeOT.java,v 1.5 2009-03-02 15:31:23 mario Exp $
 */
package org.ceteca.explica.core.common;

import java.io.Serializable;
import java.math.BigDecimal;

import org.ceteca.explica.core.InterfaceExplica;

/**
 * Store class to hold the data of a VAT type.
 * <br/>
 * Responsibilities:
 * <li>
 * 	<ul> Store of VAT type data for exchanging data among presentation, 
 * business and data access layers. </ul>
 * </li>.
 * <br/>
 * @author Mario García García <mario@imagos.es>
 * Copyright (c) 2007 Fundación Centro Tecnolóxico da Carne
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * <br/>
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * <br/>
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
public class VatTypeOT extends BaseVO implements Serializable {
	/**
	 * Internal id of the VAT type.
	 */
	private long idVat;
	/**
	 * Description of the VAT type.
	 */
	private String description;
	/**
	 * Tax percentage of the VAT type.
	 */
	private BigDecimal taxPercentage;
	/**
	 * Rec equi percentage of the VAT type.
	 */
	private BigDecimal recEquiPercentage;
	
	/**
	 * Version of the VAT type used by Hibernate for optimistic concurrency control.
	 */
	private Integer version = new Integer(0);
	
	private static final long serialVersionUID = 10000002;
	
	/**
	 * Default VatTypeOT constructor.
	 */
	public VatTypeOT() {
	}
	
	/**
	 * Gets the version of the VAT type used by Hibernate for optimistic concurrency control.
	 * @return Integer, version of the group.
	 */
	public Integer getVersion() {
		return version;
	}
	/**
	 * Sets up the version of the VAT type used by Hibernate for optimistic concurrency control.
	 * @param version Integer, version of the VAT type.
	 */
	public void setVersion(Integer version) {
		this.version = version;
	}

	/**
	 * Gets the description of the VAT type.
	 * @return String, description of the VAT type.
	 */
	public String getDescription() {
		return description;
	}
	/**
	 * Sets up the description of the VAT type.
	 * @param description String, description of the VAT type.
	 */
	public void setDescription(String description) {
		this.description = description;
	}

	/**
	 * Gets the identifier of the VAT type.
	 * @return String, identifier of the VAT type.
	 */
	public long getIdVat() {
		return idVat;
	}
	/**
	 * Sets up the identifier of the VAT type.
	 * @param idGroup String, identifier of the VAT type.
	 */
	public void setIdVat(long idVat) {
		this.idVat = idVat;
	}
	
	/**
	 * Gets the rec. equi. percentage of the VAT type.
	 * @return BigDecimal, rec. equi. percentage of the VAT type.
	 */
	public BigDecimal getRecEquiPercentage() {
		return recEquiPercentage;
	}
	/**
	 * Sets upthe rec. equi. percentage of the VAT type.
	 * @param recEquiPercentage BigDecimal, rec. equi. percentage of the VAT type.
	 */
	public void setRecEquiPercentage(BigDecimal recEquiPercentage) {
		this.recEquiPercentage = recEquiPercentage;
	}
	
	/**
	 * Gets the tax percentage of the VAT type.
	 * @return BigDecimal, tax percentage of the VAT type.
	 */
	public BigDecimal getTaxPercentage() {
		return taxPercentage;
	}
	/**
	 * Sets up the tax percentage of the VAT type.
	 * @param taxPercentage BigDecimal, tax percentage of the VAT type.
	 */
	public void setTaxPercentage(BigDecimal taxPercentage) {
		this.taxPercentage = taxPercentage;
	}

	/**
	 * Implementation of the equals method provided by the serializable interface.
	 */
	public boolean equals(Object other) {
        if (this == other) 
        	return true;
        if ( !(other instanceof VatTypeOT) ) 
        	return false;

        final VatTypeOT vatType = (VatTypeOT) other;

        if ( vatType.getDescription() == null )
        	return this.getDescription() == null;
        else if ( !vatType.getDescription().equals( this.getDescription() ) ) 
        	return false;

        return true;
    }

	/**
	 * Implementation of the hashCode method provided by the serializable interface.
	 */
    public int hashCode() {
        int result;
        if (this == null || this.getDescription() == null)
        	result = 0;
        else
        	result = this.getDescription().hashCode();
        return result;
    }
    
	/**
	 * Implementation of the toString() method to show the data of the ExtFieldOT
	 * formatted.
	 */
	public String toString() {
		StringBuffer result = new StringBuffer();
		try {
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
			result.append("\nID: ");
			result.append(this.idVat);
			result.append("\nDESCRIPTION: ");
			result.append(this.description);
			result.append("\nTAX PERCENTAGE: ");
			result.append(this.taxPercentage);
			result.append("\nREC. EQUI. PERCENTAGE: ");
			result.append(this.recEquiPercentage);
			result.append("\n%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
		}
		catch (Exception ex) {
			System.out.println("Error formatting VatTypeOT!");
			ex.printStackTrace();
			return null;
		}
		
		return result.toString();
	}
    
	@Override
	public boolean equals(Long id) {
		return id != null && this.idVat == id.longValue();
	}
	
	@Override
	public long getInternalId() {
		return this.idVat;
	}

	@Override
	public String getInternalValue() {
		return this.description;
	}
	
	@Override
	public String getEntityId() {
		return InterfaceExplica.EXPLICA_ENTITY_VATTYPE_ID;
	}

	/**
	 * Returns tag Id assigned to CVS source file.
	 */
	public static String getRevision() {
		return "$Id: VatTypeOT.java,v 1.5 2009-03-02 15:31:23 mario Exp $";
	}	
}
